package com.jy.modules.cims.component.image.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.common.sysUtils.SpringContextUtils;
import com.jy.modules.cims.component.image.TransferImagesQueue;
import com.jy.modules.cims.component.image.service.QueryTransferImagesService;

/**
 * @description QueryTransferImagesTask
 * @author shengzhoutao
 * @date 2015-09-29
 */
@Component
public class QueryTransferImagesTask extends AbstractTransferImagesTask {

	@Autowired
	private SpringContextUtils springContextUtils;

	@Override
	public void doSomething() {
		// 控制队列处理个数
		if (TransferImagesQueue.downQueue.size() > WAIT_QUEUE_SIZE) {
			sleep(1000 * 1 * 1);
			return;
		}

		if (TransferImagesQueue.downQueue.isEmpty() || CimsConstant.mmediatelyQuery) {
			int count = springContextUtils.getBean(QueryTransferImagesService.class).addDownQueue();
			if (count == 0) {
				this.suspendQuery();
				sleep(1000 * 20);
			} else {
				sleep(1000 * 10);
			}
		} else {
			sleep(1000 * 2);
			return;
		}
	}

}
